﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class WS22FDISMData : BaseFunction
    {
        
        public WS22FDISMData()
            : base()
        {
           
        }
        public WS22FDISMData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet GetRawData(DataRow dwABPOS)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            string ARTICLE,FDATE,EDATE;
            ARTICLE = dwABPOS["ARTICLE"].ToString().Trim();
            FDATE = dwABPOS["FDATE"].ToString().Trim();
            EDATE = dwABPOS["EDATE"].ToString().Trim();
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
          
                #region
                or1.CommandText = " SELECT DISTINCT B.WAKUNDNR,TRIM(B.WAART)||'-'||TRIM(B.WAVAR) AS ARTICLE,TO_NUMBER(B.WARFDDIS)*0.01 AS FDDIS, "
                    + " TO_NUMBER(C.WTGFDISM)*0.01 AS FDISM,A.ABPNEUDAT, "
                    + " A.ABPAUFKRS||'-'||TO_NUMBER(A.ABPAUFLFD)||'-'||TO_NUMBER(A.ABPAUFPOS)AS ORDERNO "
                    + " FROM WASTAMM B,ABPOS A,WTGEW C "
                    + " WHERE B.WAMANDANT = A.ABPMANDANT  "
                    + " AND B.WAKUNDNR = A.ABPKUNDNR AND B.WAART = A.ABPART AND B.WAVAR = TRIM(A.ABPVAR)  "
                    + " AND B.WAMANDANT = C.WTGMANDANT AND B.WAKUNDNR = C.WTGKUNDNR AND B.WAART = C.WTGART "
                    + " AND B.WAVAR = C.WTGVAR AND B.WAMANDANT ='00' AND B.WAKUNDNR = '00000000' "
                    + " AND (A.ABPAUFART = 'DI' OR A.ABPAUFKRS LIKE 'W%') "
                    + " AND A.ABPNEUDAT >= '" + FDATE + "' AND A.ABPNEUDAT <= '" + EDATE + "' "
                    + " AND TRIM(B.WAART)||'-'||TRIM(B.WAVAR) LIKE '" + ARTICLE + "%'  "                    
                    ;

                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WS22FDISM";
                   
                }
                set4Return.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        
        public DataSet BuildGBBEW(DataRow dwUI)
        {
            string progress = "查询完成";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                EventDispatcher.Instance.RaiseStatus("查询开始", StatusEventType.StartProgress);
                setResult = GetRawData(dwUI);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}